package com.dc.refactoring._4_简化条件表达式._5_ReplaceNastedConditionalWithGuardClauses;

import lombok.Data;


@Data
public class Demo {
    private boolean isDead = false;
    private boolean isSeparated = true;
    private boolean isRetired = true;

    /**
     * 改造前_所有的条件分支，都对应了一个返回值
     */
    public double getPayAmountOld(){
        double result;
        if (isDead){
            result = deadAmount();
        }else if (isSeparated){
            result = separatedAmount();
        }else if (isRetired){
            result = retiredAmount();
        }else {
            result = normalPayAmount();
        }
        return result;
    }

    /**
     * 改造后_将符合条件的值处理后，直接返回，挺高代码的可读性
     */
    public double getPayAmountNew(){
        if (isDead){
            return deadAmount();
        }
        if (isRetired){
            return retiredAmount();
        }
        if (isSeparated){
            return separatedAmount();
        }
        return normalPayAmount();
    }

    private double deadAmount(){
        return 0.3;
    }

    private double separatedAmount(){
        return 0.9;
    }

    private double retiredAmount(){
        return 5.6;
    }

    private double normalPayAmount(){
        return 100.3;
    }
}
